package fr.utbm.lo53;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class LO53ipsActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    Button btnOff ; 
    Button btnOn ;
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Settings.createInstance(this);
        Network.createInstance(this);
        btnOff = (Button)findViewById(R.id.offline);
        btnOff.setOnClickListener(this);
        btnOn = (Button)findViewById(R.id.online);
        btnOn.setOnClickListener(this);
        if (!Settings.getInstance().hasIp()) {
        	Settings.getInstance().setIp("192.168.1.1");
        }
        if (!Settings.getInstance().hasPort()) {
        	Settings.getInstance().setPort("8080");
        }
        
    }
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	int id = item.getItemId();
        // Handle item selection
        switch (id)
        {
        case R.id.settings:
        	Intent settingsActivity = new Intent(getBaseContext(), SettingsActivity.class);
        	startActivity(settingsActivity);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
	public void onClick(View v) {
		if (v == btnOff) {
			Intent offActivity = new Intent(getBaseContext(), OffActivity.class);
        	startActivity(offActivity);
		}
		if (v == btnOn) {
			Intent onActivity = new Intent(getBaseContext(), OnActivity.class);
        	startActivity(onActivity);		
		}
	}
}